package com.gec.oasys.service.impl;

import com.gec.oasys.dao.SysDepartMentMapper;
import com.gec.oasys.pojo.SysDepartMent;
import com.gec.oasys.service.SysDepartMentService;
import com.gec.oasys.util.SoulPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class SysDepartMentServiceImpl implements SysDepartMentService {
    @Autowired
    private SysDepartMentMapper sysDepartMentMapper;
    @Override
    public SysDepartMent selectByPrimaryKey(Integer id) {
        return sysDepartMentMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<SysDepartMent> querySysDepartment(SysDepartMent sysDepartMent) {
        return sysDepartMentMapper.querySysDepartment(sysDepartMent);
    }

    @Override
    public int deleteByPrimaryKey(Integer id) {
        return sysDepartMentMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int deletesByPrimaryKey(String[] strId) {
        for (String strid : strId) {
            sysDepartMentMapper.deleteByPrimaryKey(Integer.parseInt(strid));
        }
        return strId.length;
    }

    @Override
    public List<SysDepartMent> getSysDepartMentTreeDateById(Integer id){
        List<SysDepartMent> childSysDepartMent=sysDepartMentMapper.querySysDepartMentByPid(id);
        diguiTreee(childSysDepartMent);
        System.out.println();
        return childSysDepartMent;
    }
    public void diguiTreee(List<SysDepartMent> sysDepartMentList){
        for(SysDepartMent sysDepartMent:sysDepartMentList){
            int pid=sysDepartMent.getId();
            List<SysDepartMent> sysChildDepartMentList=sysDepartMentMapper.querySysDepartMentByPid(pid);
            if (sysChildDepartMentList!=null&& sysChildDepartMentList.size()>0){
                sysDepartMent.setChildren(sysChildDepartMentList);
                diguiTreee(sysChildDepartMentList);
            }
        }
    }
    @Override
    public int insert(SysDepartMent record){
        return sysDepartMentMapper.insert(record);
    }
    @Override
    public int updateByPrimaryKey(SysDepartMent record){
        return sysDepartMentMapper.updateByPrimaryKey(record);
    }
    @Override
    public Object dataGrid(SoulPage<SysDepartMent> soulPage) {
        return soulPage.setData(sysDepartMentMapper.dataGrid(soulPage,(SysDepartMent) soulPage.getObj()));
    }
}
